﻿using System;
using System.Collections.Generic;

namespace HobSoft.SoccerBet2014.Domain.Models.KeyHelper
{
    public class KeyGenerateHelper
    {
        static Dictionary<Type, IModelKeyGenerate> ModelKeyGenerateTable = new Dictionary<Type, IModelKeyGenerate>();
        static KeyGenerateHelper()
        {
            ModelKeyGenerateTable.Add(typeof(Game), new GameKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(Market), new MarketKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(Odds), new OddsKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(Tournament), new TournamentKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(BFMarket), new BFMarketKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(BFRunner), new BFRunnerKeyGenerate());
            ModelKeyGenerateTable.Add(typeof(Site.SiteContext), new SiteContextKeyGenerate());
        }

        public static string Create<T>(T mod) where T : Core.IModel
        {
            Type type = typeof(T);
            if (!ModelKeyGenerateTable.ContainsKey(type))
                throw new ArgumentNullException("ModelKeyGenerateTable");
            var keyGen = ModelKeyGenerateTable[type];
            var keyGenT = keyGen as IModelKeyGenerate<T>;
            if (keyGenT == null)
                throw new ArgumentNullException("ModelKeyGenerateTable");
            return keyGenT.Create(mod);
        }

        public static string Create<T>(params object[] args) where T : Core.IModel
        {
            Type type = typeof(T);
            if (!ModelKeyGenerateTable.ContainsKey(type))
                throw new ArgumentNullException("ModelKeyGenerateTable");

            var keyGen = ModelKeyGenerateTable[type];
            return keyGen.Create(args);
        }
    }
}
